/**
 * 
 */
package com.skyme.automation.generate.common.db;

import java.util.ArrayList;
import java.util.List;

import com.skyme.automation.generate.common.ResourceString;
import com.skyme.automation.generate.common.db.impl.db2.DB2DBManager;
import com.skyme.automation.generate.common.db.impl.hsqldb.HSQLDBDBManager;
import com.skyme.automation.generate.common.db.impl.mysql.MySQLDBManager;
import com.skyme.automation.generate.common.db.impl.oracle.OracleDBManager;
import com.skyme.automation.generate.common.db.impl.postgres.PostgresDBManager;
import com.skyme.automation.generate.common.db.impl.sqlite.SQLiteDBManager;
import com.skyme.automation.generate.common.db.impl.sqlserver.SqlServerDBManager;
import com.skyme.automation.generate.common.db.impl.standard_sql.StandardSQLDBManager;

/**
 * 数据库管理类
 * 
 * @author zhangfeng
 * 
 */
public class DBManagerFactory {

	// 数据库管理列表
	private static final List<DBManager> DB_LIST = new ArrayList<DBManager>();
	// 显示的数据库列表
	private static final List<String> DB_ID_LIST = new ArrayList<String>();
	
	static {
		new StandardSQLDBManager();
		new DB2DBManager();
		new HSQLDBDBManager();
		new MySQLDBManager();
		new OracleDBManager();
		new PostgresDBManager();
		new SQLiteDBManager();
		new SqlServerDBManager();
	}

	static void addDB(DBManager manager) {
		DB_LIST.add(manager);
		DB_ID_LIST.add(manager.getId());
	}

	public static DBManager getDBManager(String database) {
		for (DBManager manager : DB_LIST) {
			if (manager.getId().equals(database)) {
				return manager;
			}
		}

		throw new IllegalArgumentException(
				ResourceString
						.getResourceString("error.database.is.not.supported")
						+ database);
	}

	public static List<String> getAllDBList() {
		return DB_ID_LIST;
	}

}
